﻿using CCWin;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TelephoneYiShou.XQL
{
    public partial class FrmEmpperFormance : Skin_Mac
    {
        DataTable dt;
        string loginname;
        string sql;
        public FrmEmpperFormance(string name)
        {
            InitializeComponent();
            loginname = name;
        }
        //订单数
        private void butta_Click(object sender, EventArgs e)
        {
            int count = dataGridView1.RowCount;//订单数量
            MessageBoxEx.Show("您一共做成订单"+count.ToString()+"比");
        }
        //总金额
        private void button1_Click(object sender, EventArgs e)
        {
            double sum = 0;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                sum += Convert.ToDouble(dt.Rows[i][8].ToString());
            }
            MessageBoxEx.Show("您一共收入"+sum.ToString()+"元");
        }
        int i, start;//i表示总行数，start表示当前位置
        int size = 6;//size表示一页显示的数量
        private void FrmEmpperFormance_Load(object sender, EventArgs e)
        {
            label1.Text = "当前登录的是:"+ loginname;
            sql = string.Format("select e.Employeeid '个人编号',orderid '订单编号',c.CommodityName '手机型号',c.colour '颜色',cl.ClientName '客户姓名',Number '销售数量',OrderTime '销售时间',Paytype '支付方式',Moneysum '该单总金额'from SellGoods s,Commodity c,Client cl ,Employee e where s.ClientID=cl.ClientID and s.CommodityID= c.CommodityID and s.Employeeid = e.EmployeeID and e.EmployeeName = '{0}'", loginname);
            dt = DBHelper.GetDataTable(sql);
            i = dt.Rows.Count;//获取数据的条数
            show(0, size);
            label2.Text = string.Format("第{0}页/共{1}页 共{2}条数据", start + 1, i / size + 1, i);//显示数据
        }
        //卖出手机台数
        private void button2_Click(object sender, EventArgs e)
        {
            int sum = 0;
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                sum += Convert.ToInt32(dt.Rows[i][5].ToString());
            }
            MessageBoxEx.Show("您一共卖出"+sum.ToString()+"台手机");
        }
        //退出
        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }
        //下一页
        private void buttnextpage_Click(object sender, EventArgs e)
        {
            if (start + 1 > i / size)
            {
                MessageBoxEx.Show("已是尾页");
                show(start * size, size);
            }
            else
            {
                start = start + 1;
                show(start * size, size);
            }
            label2.Text = string.Format("第{0}页/共{1}页 共{2}条数据", start + 1, i / size + 1, i);//显示数据
        }
        //上一页
        private void buttstatrepage_Click(object sender, EventArgs e)
        {
            if (start < 1)
            {
                MessageBoxEx.Show("已是第一页");
                show(0, size);
            }
            else
            {
                start = start - 1;
                show(start * size, size);
            }
            label2.Text = string.Format("第{0}页/共{1}页 共{2}条数据", start + 1, i / size + 1, i);//显示数据
        }
        //搜素
        private void buttselect_Click(object sender, EventArgs e)
        {
            start = 0;//初始化页数
            string gonshang = textgs.Text;
            if (string.IsNullOrEmpty(gonshang))
            {
                MessageBoxEx.Show("请输入要搜索的内容");
                return;
            }
            //按客户姓名查询
            if (comanxuanxiang.Text=="客户姓名")
            {
                sql = string.Format("select e.Employeeid '个人编号',orderid '订单编号',c.CommodityName '手机型号',c.colour '颜色',cl.ClientName '客户姓名',Number '销售数量',OrderTime '销售时间',Paytype '支付方式',Moneysum '该单总金额'from SellGoods s,Commodity c,Client cl ,Employee e where s.ClientID=cl.ClientID and s.CommodityID= c.CommodityID and s.Employeeid = e.EmployeeID and e.EmployeeName = '{0}' and cl.ClientName like '%{1}%'", loginname, gonshang);
                dt = DBHelper.GetDataTable(sql);
                i = dt.Rows.Count;//获取数据的条数
                if (i == 0)
                {
                    MessageBoxEx.Show("没有" + gonshang + "的订单");
                }
                else
                {
                    show(0, size);
                    label2.Text = string.Format("第{0}页/共{1}页 共{2}条数据", start + 1, i / size + 1, i);//显示数据
                }
            }
            //按商品名称查询
            if (comanxuanxiang.Text == "商品名称")
            {
                sql = string.Format("select e.Employeeid '个人编号',orderid '订单编号',c.CommodityName '手机型号',c.colour '颜色',cl.ClientName '客户姓名',Number '销售数量',OrderTime '销售时间',Paytype '支付方式',Moneysum '该单总金额'from SellGoods s,Commodity c,Client cl ,Employee e where s.ClientID=cl.ClientID and s.CommodityID= c.CommodityID and s.Employeeid = e.EmployeeID and e.EmployeeName = '{0}' and c.CommodityName like '%{1}%'", loginname, gonshang);
                dt = DBHelper.GetDataTable(sql);
                i = dt.Rows.Count;//获取数据的条数
                if (i == 0)
                {
                    MessageBoxEx.Show("没有" + gonshang + "的订单");
                }
                else
                {
                    show(0, size);
                    label2.Text = string.Format("第{0}页/共{1}页 共{2}条数据", start + 1, i / size + 1, i);//显示数据
                }
            }
            //按支付方式
            if (comanxuanxiang.Text == "支付方式")
            {
                sql = string.Format("select e.Employeeid '个人编号',orderid '订单编号',c.CommodityName '手机型号',c.colour '颜色',cl.ClientName '客户姓名',Number '销售数量',OrderTime '销售时间',Paytype '支付方式',Moneysum '该单总金额'from SellGoods s,Commodity c,Client cl ,Employee e where s.ClientID=cl.ClientID and s.CommodityID= c.CommodityID and s.Employeeid = e.EmployeeID and e.EmployeeName = '{0}' and Paytype like '%{1}%'", loginname, gonshang);
                dt = DBHelper.GetDataTable(sql);
                i = dt.Rows.Count;//获取数据的条数
                if (i == 0)
                {
                    MessageBoxEx.Show("没有" + gonshang + "的订单");
                }
                else
                {
                    show(0, size);
                    label2.Text = string.Format("第{0}页/共{1}页 共{2}条数据", start + 1, i / size + 1, i);//显示数据
                }
            }
        }

        //show
        public void show(int i, int j)
        {           
            SqlDataAdapter sqlada = DBHelper.GetDataTableFenYe(sql);
            DataSet ds = new DataSet();
            sqlada.Fill(ds, i, j, "[SellGoods]");//把数据库表中的i-j的记录数用来填充数据集
            dataGridView1.DataSource = ds.Tables[0];
            ds = null;//清空数据集
        }
    }
}
